package en.edu.zxj.rabbit.extensions.demo.config;

import com.rabbitmq.client.Return;
import en.edu.zxj.rabbit.extensions.demo.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-09-21
 * @time: 20:41:55
 */
@Configuration
public class DelayConfig {
    @Bean("delayExchange")
    public Exchange delayExchange() {
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE_NAME).durable(true).delayed().build();
    }

    @Bean("delayQueue")
    public Queue delayQueue() {
        return QueueBuilder.durable(Constants.DELAY_QUEUE_NAME).build();
    }

    @Bean("delayBind")
    public Binding delayBind(@Qualifier("delayQueue") Queue queue, @Qualifier("delayExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(Constants.DELAY_ROUTING_KEY).noargs();
    }


}
